package com.katze.common;

import org.apache.commons.lang3.time.FastDateFormat;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import java.util.TimeZone;

/**
 * 说  明：
 * 作  者：zf.zeng
 * 日  期：2022-10-07 (星期五)
 **/
public class DatePattern {
    public static final String NORM_DATE_PATTERN = "yyyy-MM-dd";
    public static final FastDateFormat NORM_DATE_FORMAT = FastDateFormat.getInstance(NORM_DATE_PATTERN);

    public static final String NORM_TIME_PATTERN = "HH:mm:ss";
    public static final FastDateFormat NORM_TIME_FORMAT = FastDateFormat.getInstance(NORM_TIME_PATTERN);

    public static final String NORM_DATETIME_MINUTE_PATTERN = "yyyy-MM-dd HH:mm";
    public static final FastDateFormat NORM_DATETIME_MINUTE_FORMAT = FastDateFormat.getInstance(NORM_DATETIME_MINUTE_PATTERN);

    public static final String NORM_DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
    public static final FastDateFormat NORM_DATETIME_FORMAT = FastDateFormat.getInstance(NORM_DATETIME_PATTERN);

    public static final String NORM_DATETIME_MS_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS";
    public static final FastDateFormat NORM_DATETIME_MS_FORMAT = FastDateFormat.getInstance(NORM_DATETIME_MS_PATTERN);

    public static final String PURE_DATE_PATTERN = "yyyyMMdd";
    public static final FastDateFormat PURE_DATE_FORMAT = FastDateFormat.getInstance(PURE_DATE_PATTERN);

    public static final String PURE_TIME_PATTERN = "HHmmss";
    public static final FastDateFormat PURE_TIME_FORMAT = FastDateFormat.getInstance(PURE_TIME_PATTERN);

    public static final String PURE_DATETIME_PATTERN = "yyyyMMddHHmmss";
    public static final FastDateFormat PURE_DATETIME_FORMAT = FastDateFormat.getInstance(PURE_DATETIME_PATTERN);

    public static final String PURE_DATETIME_MS_PATTERN = "yyyyMMddHHmmssSSS";
    public static final FastDateFormat PURE_DATETIME_MS_FORMAT = FastDateFormat.getInstance(PURE_DATETIME_MS_PATTERN);

    public static final String YY_PURE_DATETIME_MS_PATTERN = "yyMMddHHmmssSSS";
    public static final FastDateFormat YY_PURE_DATETIME_MS_FORMAT = FastDateFormat.getInstance(YY_PURE_DATETIME_MS_PATTERN);

    public static final String YY_DATETIME_NOT_SECOND_PATTERN = "yyMMddHHmm";
    public static final FastDateFormat YY_DATETIME_NOT_SECOND_FORMAT = FastDateFormat.getInstance(YY_DATETIME_NOT_SECOND_PATTERN);

    public static final String HTTP_DATETIME_PATTERN = "EEE, dd MMM yyyy HH:mm:ss z";
    public static final FastDateFormat HTTP_DATETIME_FORMAT = FastDateFormat.getInstance(HTTP_DATETIME_PATTERN);

    public static final String JDK_DATETIME_PATTERN = "EEE MMM dd HH:mm:ss zzz yyyy";
    public static final FastDateFormat JDK_DATETIME_FORMAT = FastDateFormat.getInstance(JDK_DATETIME_PATTERN, Locale.ENGLISH);

    public static final String UTC_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'";
    public static final FastDateFormat UTC_FORMAT = FastDateFormat.getInstance(UTC_PATTERN, TimeZone.getTimeZone("UTC"));

    public static final String GMT_PATTERN = "EEE MMM dd yyyy HH:mm:ss 'GMT'Z";
    public static final FastDateFormat GMT_FORMAT = FastDateFormat.getInstance(GMT_PATTERN, Locale.ENGLISH);

    public DatePattern() {}

    public static String localDateTime(String... pattern) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern.length == 1? pattern[0]:PURE_DATETIME_PATTERN);
        return LocalDateTime.now().format(dateTimeFormatter);
    }

    public static String localDateTime(LocalDateTime localDateTime, String... pattern) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern.length == 1? pattern[0]:PURE_DATETIME_PATTERN);
        return localDateTime.format(dateTimeFormatter);
    }
}
